package conf

import (
	"github.com/tristin2024/config"
	"github.com/tristin2024/logs"
	"os"
)

var UrlName = make(map[string]string)

const (
	UserPrivateApi    = "USER_PRIVATE_API"
	AuthApi           = "AUTH_API"
	BagsPrivateApi    = "BAGS_PRIVATE_API"
	DataPrivateApi    = "DATA_PRIVATE_API"
	DynamicPrivateApi = "DYNAMIC_PRIVATE_API"
	FinancePrivateApi = "FINANCE_PRIVATE_API"
	IshumeiApi        = "ISHUMEI_API"
	RoomPrivateApi    = "ROOM_PRIVATE_API"
	SmsPrivateApi     = "SMS_PRIVATE_API"
	UuidManagerApi    = "UUID_MANAGER_API"
	OssApi            = "OSS_ACCESS_URL"
)

var (
	Env        string
	PostgreSQL struct {
		Host      string `yaml:"host"`
		Port      string `yaml:"port"`
		User      string `yaml:"user"`
		Password  string `yaml:"password"`
		DbDynamic string `yaml:"dbDynamic"`
	}
	Redis struct {
		Host     string `yaml:"host"`
		Port     string `yaml:"port"`
		Password string `yaml:"password"`
		Db3      int    `yaml:"db3"`
	}
)

func init() {
	apiPrivate := []string{
		UserPrivateApi,
		AuthApi,
		BagsPrivateApi,
		DataPrivateApi,
		DynamicPrivateApi,
		FinancePrivateApi,
		IshumeiApi,
		RoomPrivateApi,
		SmsPrivateApi,
		UuidManagerApi,
		OssApi,
	}
	if err := config.Viper.UnmarshalKey("env", &Env); err != nil {
		panic(err)
	}
	if err := config.Viper.UnmarshalKey("postgresql", &PostgreSQL); err != nil {
		panic(err)
	}
	if err := config.Viper.UnmarshalKey("redis", &Redis); err != nil {
		panic(err)
	}
	for _, v := range apiPrivate {
		UrlName[v] = os.Getenv(v)
	}
	logs.Std.Info("conf init success")
}
